<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<body>
<div class="modal fade" id="addUserModal" tabindex="-1" role="dialog" aria-labelledby="addUserModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
							&times;
						</button>
						<h4 class="model-title" id="addUserModalLabel">
							添加学生
						</h4>
					</div>
					<div class="modal-body">
						<form id="addUserForm" method="POST">
						
						<label>邮箱地址:&nbsp;&nbsp;</label><input type="text" name="email" placeholder="请输入邮箱地址"><span class="emailtext"></span><br/>
						<label>密码:&nbsp;&nbsp;</label><input type="password" name="password1" placeholder="请输入密码" /><span class="password1text"></span><br/>
						<label>重复密码:&nbsp;&nbsp;</label><input type="password" name="password2" placeholder="请再次输入密码" /><span class="password2text"></span><br/>
						<label>姓名:&nbsp;&nbsp;</label><input type="text" name="userName" placeholder="请输入姓名"><span class="nametext"></span><br/>
						<label>电话号码:&nbsp;&nbsp;</label><input type="text" name="telephone" placeholder="请输入电话号码"><span class="teltext"></span><br/>
						<label>性别:&nbsp;&nbsp;</label><select name="gender">
						<option value="1">男</option>
						<option value="0">女</option>
						</select><br/>
						<label>地址:&nbsp;&nbsp;</label><input type="text" name="address" placeholder="请输入地址"><span class="addresstext"></span><br/>
						<label>生日:&nbsp;&nbsp;</label><input type="date" name="birthday" placeholder="请输入生日日期"><span class="birthdaytext"></span><br/>
						
						</form>
					</div>
					
					<div class="modal-footer">
						<button type="button" class="btn btn-default saveUserBtn" data-dismiss="modal">添加</button>
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					</div>
					
				</div>
			</div>
		
		</div>
		<div class="modal fade" id="uploadFileModal" tabindex="-1" role="dialog" aria-labelledby="uploadFileModalLabel">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
						&times;
						</button>
						<h4 class="modal-title" id="uploadFileModalLabel">
							上传
						</h4>
					</div>
					<div class="modal-body">
						<input id="uploadFile" name="uploadFile" type="file">
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
						<button id="subjectStudentSaveBtn" type="button" class="btn btn-primary">保存</button>
					</div>
				</div>
			</div>
		</div>
		<div class="modal fade" id="editUserModal" tabindex="-1" role="dialog" aria-labelledby="editUserModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
							&times;
						</button>
						<h4 class="model-title" id="editUserModalLabel">
							修改学生信息
						</h4>
					</div>
					<div class="modal-body">
						<form id="editUserForm" method="POST">
						<label>ID:</label><span class="idtext"></span><br/>
						<label>邮箱地址:&nbsp;&nbsp;</label><input type="text" name="email" placeholder="请输入邮箱地址"><span class="emailtext"></span><br/>
						<label>密码:&nbsp;&nbsp;</label><input type="password" name="password1" placeholder="请输入密码" /><span class="password1text"></span><br/>
						<label>重复密码:&nbsp;&nbsp;</label><input type="password" name="password2" placeholder="请再次输入密码" /><span class="password2text"><br/>
						<label>姓名:&nbsp;&nbsp;</label><input type="text" name="userName" placeholder="请输入姓名"><span class="nametext"></span><br/>
						<label>电话号码:&nbsp;&nbsp;</label><input type="text" name="telephone" placeholder="请输入电话号码"><span class="teltext"></span><br/>
						<label>性别:&nbsp;&nbsp;</label><select name="gender">
						<option value="1">男</option>
						<option value="0">女</option>
						</select><br/>
						<label>地址:&nbsp;&nbsp;</label><input type="text" name="address" placeholder="请输入地址"><span class="addresstext"></span><br/>
						<label>生日:&nbsp;&nbsp;</label><input type="date" name="birthday" placeholder="请输入生日日期"><span class="birthdaytext"></span><br/>
						
						</form>
					</div>
					
					<div class="modal-footer">
						<button type="button" class="btn btn-default updateUserBtn" data-dismiss="modal">更改</button>
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					</div>
					
				</div>
			</div>
		
		</div>
					<div class="row">
							<div class="col-xs-12">
								<!-- PAGE CONTENT BEGINS -->
								<div class="row">
									<div class="col-xs-12">
									<button id="showAddUserBtn" class="btn btn-primary">
										<i class="ace-icon fa fa-plus align-top bigger-125"></i>
										添加学生信息
									</button>
									<button id="addStudentBtn" class="btn btn-primary">
										<i class="ace-icon fa fa-plus align-top bigger-125"></i>
										批量添加学生信息
									</button>
										<table id="sample-table-1" class="table table-striped table-bordered table-hover">
											<thead>
												<tr>
													<th class="center">
<!-- 														<label class="position-relative"> -->
<!-- 															<a href="add"> -->
<!-- 																Add User -->
<!-- 															</a> -->
<!-- 														</label> -->
													</th>
													<th>ID</th>
													<th>Name</th>
													<th class="hidden-480">Telephone</th>

													<th>
														<i class="ace-icon fa fa-clock-o bigger-110 hidden-480"></i>
														Email
													</th>
													<th class="hidden-480">Address</th>

													<th>Birthday</th>
													<th>gender</th>
													<th>Last_lock_time</th>
													<th>Login_fail_count</th>
													<th>Action</th>
												</tr>
											</thead>

											<tbody>
											<c:forEach items="${userList }" var="userVO">
												<tr>
													<td class="center">
														<label class="position-relative">
															<input type="checkbox" class="ace" />
															<span class="lbl"></span>
														</label>
													</td>

													<td>
														${userVO.id }
													</td>
													
													<td>${userVO.name }</td>
													<td class="hidden-480">${userVO.tel }</td>
													<td>${userVO.email }</td>

													<td class="hidden-480">
														${userVO.address }
													</td>
													<td>
														${userVO.birthday }
									
													</td>
													
													<c:if test="${userVO.gender == 1}">
														<td>男</td>
													</c:if>
													
													<c:if test="${userVO.gender == 0}">
														<td>女</td>
													</c:if>
													
													<td>${userVO.last_lock_time }</td>
													<td>${userVO.login_fail_count }</td>
													<td>
														
															
															
															<button class="btn btn-xs btn-info showEditUserBtn" >
																
																	<i class="ace-icon fa fa-pencil bigger-120" >
																	
																	</i>
																
																
															</button>
															
															
															
															
															<a href="delete/${user.id }" onclick="javascript:return del_sure()">
															<button class="btn btn-xs btn-danger">
																<i class="ace-icon fa fa-trash-o bigger-120"></i>
															</button>
															</a>
															
														

														<div class="hidden-md hidden-lg">
															<div class="inline position-relative">
																<button class="btn btn-minier btn-primary dropdown-toggle" data-toggle="dropdown" data-position="auto">
																	<i class="ace-icon fa fa-cog icon-only bigger-110"></i>
																</button>

																<ul class="dropdown-menu dropdown-only-icon dropdown-yellow dropdown-menu-right dropdown-caret dropdown-close">
																	<li>
																		<a href="#" class="tooltip-info" data-rel="tooltip" title="View">
																			<span class="blue">
																				<i class="ace-icon fa fa-search-plus bigger-120"></i>
																			</span>
																		</a>
																	</li>

																	<li>
																		<a href="#" class="tooltip-success" data-rel="tooltip" title="Edit">
																			<span class="green">
																				<i class="ace-icon fa fa-pencil-square-o bigger-120"></i>
																			</span>
																		</a>
																	</li>

																	<li>
																		<a href="#" class="tooltip-error" data-rel="tooltip" title="Delete">
																			<span class="red">
																				<i class="ace-icon fa fa-trash-o bigger-120"></i>
																			</span>
																		</a>
																	</li>
																</ul>
															</div>
														</div>
													</td>
												</tr>
												</c:forEach>
											</tbody>
										</table>
									</div><!-- /.span -->
								</div><!-- /.row -->
								</div>
								</div>
			<script type="text/javascript">
			$('#addStudentBtn').click(function(){
				$('#uploadFileModal').modal('show');
				});
			$('#subjectStudentSaveBtn').click(function(){
				$.ajaxFileUpload({
					type:'POST',
					url:'${pageContext.request.contextPath}/uploadFile',
					secureuri:false,//是否启用安全提交
					fileElementId:'uploadFile',
					dataType:'json',
					success:function(data){
						if(data.success){
							alert("批量添加成功");
							window.location.reload();
						}else{
							alert("批量添加错误");
						}
					},
					error:function(data,stutus,e){
						alert("系统繁忙"+e);
					}
				});
// 				$.ajaxFileUpload({
// 					url:'${pageContext.request.contextPath}/uploadFile',
// 					secureuri:false,
// 					fileElementId:'uploadFile',
// 					dataType:'json',
// 					complete:function(data){
// 						},
// 					success:function(data, status){
// 							if(data.success){
// 								alert('批量添加成功');
// 								window.location.reload();
// 								} else{
// 									alert(data.messageMap.message);
// 									}
// 						},
// 					error:function(data, status, e){
// 						alert(e);
// 						}
// 					});
				});
			
			$("#showAddUserBtn").click(function(){
				$("#addUserModal").modal("show");
				});
			
			$(".saveUserBtn").click(function(){
				var email = $("#addUserForm input[name='email']").val();
				var password = $("#addUserForm input[name='password1']").val();
				var password2 = $("#addUserForm input[name='password2']").val();
				if(password != password2){
					$("#addUserForm .password2text").text("两次密码不一样");
// 					alert("两次密码不一样");
					}else{
				var name = $("#addUserForm input[name='userName']").val();
				var telephone = $("#addUserForm input[name='telephone']").val();
				var gender = $("#addUserForm select[name='gender']").val();
				var address = $("#addUserForm input[name='address']").val();
				var birthday = $("#addUserForm input[name='birthday']").val();
// 				alert(email+"   "+password+"   "+name+"   "+telephone+"   "+gender+"   "+address+"   "+birthday);
				$.ajax({
					type:'POST',
					url:'${pageContext.request.contextPath}/addUser',
					secureuri:false,
					data:{
						email:email,
						password:password,
						name:name,
						tel:telephone,
						gender:gender,
						answer:address,
						birthday:birthday,
						address:address
						},
						dataType:"json",
						success:function(data){
							if(data.success){
								alert('添加成功!');
								window.location.reload();
								} else {
									alert('添加失败!');
									}
							},
						error:function(data, status, e){
	 						alert("系统繁忙"+e);
	 						}
					});
					}
				});
			$(".showEditUserBtn").click(function(){
				var userId = $(this).parent().siblings().eq(1).text();
				$.ajax({
					type:'POST',
					url:'${pageContext.request.contextPath}/toEditUser',
					data:{
						userId:userId
						},
						dataType:"json",
						success:function(data){
								$("#editUserForm .idtext").text(userId);
								$("#editUserForm input[name='email']").val(data.email);
								$("#editUserForm input[name='password1']").val(data.password);
								$("#editUserForm input[name='userName']").val(data.name);
								$("#editUserForm input[name='telephone']").val(data.tel);
								$("#editUserForm select[name='gender']").val(data.gender);
								$("#editUserForm input[name='address']").val(data.address);
								$("#editUserForm input[name='birthday']").val(data.birthday);
							},
					});
// 				$("#addUserForm input[name='email']").val();
				$("#editUserModal").modal("show");
				});
			$(".updateUserBtn").click(function(){
				var id = $("#editUserForm .idtext").text();
				var email = $("#editUserForm input[name='email']").val();
				var password = $("#editUserForm input[name='password1']").val();
				var name = $("#editUserForm input[name='userName']").val();
				var tel = $("#editUserForm input[name='telephone']").val();
				var gender = $("#editUserForm select[name='gender']").val();
				var address = $("#editUserForm input[name='address']").val();
				var birthday = $("#editUserForm input[name='birthday']").val();
				$.ajax({
					type:'POST',
					url:'${pageContext.request.contextPath}/editUser',
					data:{
						id:id,
						email:email,
						password:password,
						name:name,
						tel:tel,
						gender:gender,
						answer:address,
						birthday:birthday,
						address:address
						},
						dataType:"json",
						success:function(data){
							if(data.success){
								alert('更改成功!');
								window.location.reload();
								} else {
									alert('添加失败!');
									}
							},
						error:function(data, status, e){
	 						alert("系统繁忙"+e);
	 						}
					});
				});
		</script>
		<script type="text/javascript">
 		$('#uploadFile').ace_file_input({
 			style:'well',
 			btn_choose:'选择文件',
			btn_change:null,
			no_icon:'ace-icon fa fa-cloud-upload',
			droppable:true,
			thumbnail:'small',
			preview_error:function(filename,error_code){}
 			}).on('change',function(){
 				}); 
 		</script>
</body>
									
	


</html>
